const http = require("http");

const app = http.createServer((request, response) => {
    // 接收请求
    // console.log("请求头信息", request.headers);
    // console.log("请求URL", request.url);
    // console.log("请求方式", request.method);

    // 处理服务端逻辑...
    switch (request.url) {
        case "/users":
            if (request.method === "GET") {
                // ...
                response.end("获取用户列表");
            } else if (request.method === "POST") {
                // ...
                response.end("添加用户");
            }
        case "/login":
            // ...
            response.end("登录");
        case "/register":
            // ...
            response.end("注册");
        default:
            // ...
            response.end("Not Found.");
    }

    // 返回响应
    // response.write("<h1>Hello, Http</h1>");
    // response.write("<p>你好啊</p>");
    // response.end();
});

app.listen(3000, () => {
    console.log("http server running at http://localhost:3000");
});
